﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nature
{
    public partial class IdealGasMixture
    {
        partial void OnNCRTDCRequested()
        {
            m_ncrtdc = Model.IdealGasChemicalKinetics.Ntd;
        }

        void calc_reactionForwardRates(double[] fwd)
        {
            Model.IdealGasChemicalKinetics.CalcReactionForwardRates(this, fwd);
        }

        void calc_reactionReverseRates(double[] rev)
        {
            Model.IdealGasChemicalKinetics.CalcReactionReverseRates(this, rev);
        }


        void calc_reactionNetRates(double[] rrates)
        {
            var fwd = this.ReactionForwardRates.Data;
            var rev = this.ReactionReverseRates.Data;
            for (int ire = 0; ire < Nre; ++ire)
            {
                rrates[ire] = fwd[ire] - rev[ire];
            }
        }

        void calc_speciesChemicalNetProductionRates(double[] spNetProductionRates)
        {
            var creationRates = this.SpeciesChemicalCreationRates.Data;
            var destructionRates = this.SpeciesChemicalDestructionRates.Data;
            for (int isp = 0; isp < Nsp; ++isp)
            {
                spNetProductionRates[isp] = creationRates[isp] - destructionRates[isp];
            }
        }

        void calc_reactionTemperatureDependentCoefficients(double[] tdep)
        {
            Model.IdealGasChemicalKinetics.CalcReactionExplicitTemperatureDependencies(this, tdep);
        }

        void calc_reactionForwardConstants(double[] forwardReactionConstants)
        {
            Model.IdealGasChemicalKinetics.CalcReactionForwardConstants(this, forwardReactionConstants);
        }

        void calc_reactionReverseConstants(double[] reverseReactionConstants)
        {
            Model.IdealGasChemicalKinetics.CalcReactionReverseConstants(this, reverseReactionConstants);
        }

        void calc_speciesChemicalCreationRates(double[] speciesCreationRates)
        {
            Model.IdealGasChemicalKinetics.CalcSpeciesCreationRates(this, speciesCreationRates);
        }

        void calc_speciesChemicalDestructionRates(double[] speciesDestructionRates)
        {
            Model.IdealGasChemicalKinetics.CalcSpeciesDestructionRates(this, speciesDestructionRates);
        }

        void calc_speciesMassFractionChemicalNetProductionRates(double[] yw)
        {
            var w = this.SpeciesChemicalNetProductionRates.Data;
            var mk = this.Model.SpeciesMolarMasses;
            double ro = this.MassDensity;
            for (int isp = 0; isp < Nsp; ++isp)
            {
                yw[isp] = w[isp] * mk[isp] / ro;
            }
        }
    }
}
